/*Layui获取select选中的option */

/* 需求 */
/*
    1.本校学生
        (1)姓名
        (2)学号
        (3)学院
        (4)类别
        (5)场次
    2.外校学生
        (1)学校名字
        (2)场次
    3.本校老师
        (1)姓名
        (2)学院
        (3)类别
        (4)场次
    4.辅导员
        (1)姓名
        (2)学院
        (3)类别
        (4)场次
*/
var SetNameflag = false;
var InnerText;
var Name_box = document.getElementById("name-box"); //姓名
var School_box = document.getElementById("school-box");//学校
var Number_Box = document.getElementById("number-box");//学号
var Work_Class = document.getElementById("work-class");//学院
// var College_box = document.getElementById("college-box");//类别
var Session_box = document.getElementById("session-box");//场次
var Button_box = document.getElementById("button-box");//提交按钮

function clear_all(){  //切换不同的身份时  将输入框和选择框中的内容清空 避免提交的时候出现问题
    $("#name-input").val("");
    $("#number-input").val("");
    // $("#school-input").val("");
    //$("#college-select").val("");
    // $("#session-select").val("");
    $("#work-select").val("");
}

function reSet(){  //重置一些表单验证用到的变量  避免切换身份的时候出现问题
    name_check_flag = false;
    number_check_flag = false;
    school_check_flag = false;
    document.getElementById("check-name-box").style.display="none";
    document.getElementById("number-check-box").style.display="none";
    document.getElementById("check-school-box").style.display="none";
}


layui.use('form',function(){   //根据相应的身份设置不同的显示内容
    var form = layui.form;
    form.on('select(class-name)',function(data){
        var Value = data.value;
        var text = data.elem[data.elem.selectedIndex].text;
        form.render('select');
        if(text === "请点击选择"){
            Name_box.style.display = "none";
            School_box.style.display = "none";
            Number_Box.style.display = "none";
            Work_Class.style.display = "none";
            // College_box.style.display = "none";
            Session_box.style.display = "none";
            // Button_box.style.display = "none";
            //clear_all();
            // reSet();
        }
        if(text === "本校本科生" || text === "本校研究生"){  //如果是本校学生
            Name_box.style.display = "block";
            School_box.style.display = "none";
            Number_Box.style.display = "block";
            Work_Class.style.display = "block";
            // College_box.style.display = "block";
            Session_box.style.display = "block";
            Button_box.style.display = "block";
            $("#name-input").val("");
            document.getElementById("btn").removeAttribute("onclick");
            document.getElementById("btn").setAttribute("onclick","submit_check1()");
            //clear_all();
            // reSet();
        }
        else if(text === "外校学生"){
            Name_box.style.display = "block";
            School_box.style.display = "block";
            Number_Box.style.display = "none";
            Work_Class.style.display = "none";
            // College_box.style.display = "none";
            Session_box.style.display = "block";
            Button_box.style.display = "block";
            $("#work-select").val("");
            document.getElementById("btn").removeAttribute("onclick");
            document.getElementById("btn").setAttribute("onclick","submit_check2()");
            //clear_all();
            //reSet();
            //$("#name-input").val("外校学生");  //外校学生设置成默认姓名 = "外校学生"
            //InnerText = $("#name-input").val();
            //console.log(InnerText);
        }
        /*这里似乎还是有BUG  提交的时候还是会提交已经被隐藏的元素*/
        else if(text === "本校老师"){
            //需要验证:姓名 学院 场次
            Name_box.style.display = "block";
            School_box.style.display = "none";
            Number_Box.style.display = "none";
            Work_Class.style.display = "block";
            // College_box.style.display = "none";
            Session_box.style.display = "block";
            Button_box.style.display = "block";
            /*if(SetNameflag === false){
                $("#name-input").val(" ");
            }else{
                $("#name-input").val(document.getElementById("name-input").value);
            }*/

            document.getElementById("btn").removeAttribute("onclick");
            document.getElementById("btn").setAttribute("onclick","submit_check3()");
            //clear_all();
            // reSet();
        }
        else if(text === "辅导员"){
            Name_box.style.display = "block";
            School_box.style.display = "none";
            Number_Box.style.display = "none";
            Work_Class.style.display = "block";
            // College_box.style.display = "none";
            Session_box.style.display = "block";
            Button_box.style.display = "block";
            $("#name-input").val("");

            document.getElementById("btn").removeAttribute("onclick");
            document.getElementById("btn").setAttribute("onclick","submit_check3()");
            //clear_all();
            // reSet();
        }
    })
})
